﻿using SQLite.CodeFirst;
using System;
using System.Collections.Generic;
using System.Data.Common;
using System.Data.Entity;
using System.Data.Entity.Core.Common;
using System.Data.Entity.Core.Objects;
using System.Data.Entity.Infrastructure;
using System.Data.SQLite;
using System.Data.SQLite.EF6;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Xejen.Database.Ef.Sqlite
{
    /// <summary>
    /// 表示适用于<see langword="Sqlite"/>的<see langword="Ef"/>框架的数据库上下文
    /// </summary>
    /// <creator>marc</creator>
    [DbConfigurationType(typeof(SqliteDbConfiguration))]
    public abstract class SqliteDbContext : EfDbContext
    {
        /// <inheritdoc cref="SqliteDbContext"/>
        /// <param name="connectionString">数据库连接字符串，如：Data Source=mydatabase.db</param>
        protected SqliteDbContext(string connectionString) : this(new SQLiteConnection(connectionString))
        {

        }

        /// <inheritdoc cref="SqliteDbContext"/>
        /// <param name="existingConnection"><inheritdoc cref="EfDbContext.EfDbContext(DbConnection, bool)" path="/param[@name='existingConnection']"/></param>
        protected SqliteDbContext(DbConnection existingConnection) : this(existingConnection, true)
        {

        }

        /// <inheritdoc cref="SqliteDbContext"/>
        /// <param name="existingConnection"><inheritdoc cref="EfDbContext.EfDbContext(DbConnection, bool)" path="/param[@name='existingConnection']"/></param>
        /// <param name="contextOwnsConnection"><inheritdoc cref="EfDbContext.EfDbContext(DbConnection, bool)" path="/param[@name='contextOwnsConnection']"/></param>
        protected SqliteDbContext(DbConnection existingConnection, bool contextOwnsConnection) : base(existingConnection, contextOwnsConnection)
        {

        }

        /// <inheritdoc cref="SqliteDbContext"/>
        /// <param name="objectContext"><inheritdoc cref="EfDbContext.EfDbContext(ObjectContext, bool)" path="/param[@name='objectContext']"/></param>
        protected SqliteDbContext(ObjectContext objectContext) : this(objectContext, true)
        {

        }

        /// <inheritdoc cref="SqliteDbContext"/>
        /// <param name="objectContext"><inheritdoc cref="EfDbContext.EfDbContext(ObjectContext, bool)" path="/param[@name='objectContext']"/></param>
        /// <param name="dbContextOwnsObjectContext"><inheritdoc cref="EfDbContext.EfDbContext(ObjectContext, bool)" path="/param[@name='dbContextOwnsObjectContext']"/></param>
        protected SqliteDbContext(ObjectContext objectContext, bool dbContextOwnsObjectContext) : base(objectContext, dbContextOwnsObjectContext)
        {

        }

        /// <inheritdoc/>
        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            base.OnModelCreating(modelBuilder);
        }
    }
}
